<template>
  <div class="step-progress-bar">
    <!-- 环形进度条 -->
    <div class="circular-progress-container">
      <div class="circular-progress">
        <svg class="progress-ring" width="120" height="120">
          <circle
            class="progress-ring-circle-bg"
            stroke="#e5e7eb"
            stroke-width="6"
            fill="transparent"
            r="52"
            cx="60"
            cy="60"
          />
          <circle
            class="progress-ring-circle"
            :stroke="progressColor"
            stroke-width="6"
            fill="transparent"
            r="52"
            cx="60"
            cy="60"
            :style="circleStyle"
          />
        </svg>
        <div class="progress-text">
          <span class="progress-percentage">{{ progress }}%</span>
        </div>
      </div>
    </div>
    
    <!-- 当前消息 -->
    <div class="current-message" v-if="currentMessage">
      <p>{{ currentMessage }}</p>
    </div>
  </div>
</template>

<script>
export default {
  name: 'StepProgressBar',
  props: {
    progress: {
      type: Number,
      default: 0
    },
    currentMessage: {
      type: String,
      default: ''
    },
    isRunning: {
      type: Boolean,
      default: false
    },
    hasError: {
      type: Boolean,
      default: false
    }
  },
  computed: {
    progressColor() {
      if (this.hasError) return '#ef4444'
      if (this.progress === 100) return '#10b981'
      if (this.isRunning) return '#3b82f6'
      return '#6b7280'
    },
    circleStyle() {
      const circumference = 2 * Math.PI * 52
      const strokeDasharray = circumference
      const strokeDashoffset = circumference - (this.progress / 100) * circumference
      
      return {
        strokeDasharray: `${strokeDasharray} ${strokeDasharray}`,
        strokeDashoffset: strokeDashoffset,
        transition: 'stroke-dashoffset 0.5s ease-in-out'
      }
    }
  }
}
</script>

<style scoped>
.step-progress-bar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.circular-progress-container {
  position: relative;
}

.circular-progress {
  position: relative;
}

.progress-ring {
  transform: rotate(-90deg);
}

.progress-ring-circle-bg {
  opacity: 0.3;
}

.progress-ring-circle {
  transition: stroke-dashoffset 0.5s ease-in-out, stroke 0.3s ease;
}

.progress-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
}

.progress-percentage {
  font-size: 18px;
  font-weight: 600;
  color: #374151;
}

.current-message {
  text-align: center;
  max-width: 300px;
}

.current-message p {
  margin: 0;
  font-size: 14px;
  color: #6b7280;
  line-height: 1.4;
}

/* 动画效果 */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.progress-ring-circle.running {
  animation: pulse 2s infinite;
}
</style>